<? 
$accesslevel=1;
$title="Edit Profiles";

require("required/dbconnect.php"); 
require("required/function.php");
require("required/header.php"); 
?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?	
		
	if(!empty($_GET['action']))
	{
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_failed'>Member card number already exist</div>";
				break;
			case 2:
				$msg="<div class='dw_success'>Data Deleted</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	
$id=$_GET['id'];
$getdata=mysql_query("select * from os_member where id=".$id);
$a=mysql_fetch_array($getdata,MYSQL_ASSOC);
?>
<script language="JavaScript" type="text/javascript" src="required/js/goAjax.js"></script>	
<script type="text/javascript" src="../required/calendarDateInput.js">
</script>

<script language="javascript">
	function checkMemberCardExist(field,divName,showName) {
		
		var value = document.getElementById(field).value;
		
		var escapeValue = document.getElementById("membership_number_current").value;
		
		if(value!=""){
			changeContent('required/js/CheckMemberExist.php?escapeValue='+escapeValue+'&field='+field+'&value='+value+'&showName='+showName,divName);
		}
	}

	function formvalidate(frm)
	{
	
		
		if(document.frm.name.value=="")
		{
			alert("Please enter member name");
			document.frm.name.focus();
			return false;
		}
		
		
		
		return true;
	}
</script>


		
<table width="100%">
	<tr>
		
		
		
		<td  valign="top">
        
			<table width="100%" height="100%" >
				<tr >
					<td colspan="5" class="title">Edit Member Information</td>
				</tr>
                
				<form action="member_edit2.php" method="post" name="frm" onSubmit="return formvalidate(this)">
				
					
					<tr>
						<td colspan="5"> <div id="divMsg"><?= $msg ?></div></td>
                    </tr>
                    <tr>
						<td height="20" colspan="3"><strong>Account</strong></td>
					</tr>
					
					
					<tr valign="top">
						<td>Email</td><td>:</td><td><?= $a['email'] ?></td>
					</tr>
                    <tr valign="top">
						<td>Membership Number</td><td>:</td><td>
                        <input type="text" name="membership_number" id="membership_number" value="<?= $a['membership_number'] ?>" maxlength="50"  
                        onBlur="checkMemberCardExist('membership_number','divMemberShip','Membership Number'); return false;">
                        <input type="hidden" name="membership_number_current" id="membership_number_current" value="<?= $a['membership_number'] ?>" maxlength="50" />
                        <div id="divMemberShip"></div>
                        </td>
					</tr>
                    <tr>
                    	<Td>Member Type</td><Td>:</Td>
                        <td>
                        <?
							if($a['member_type']=="M")
							{
								$sltM="selected";
								$sltN="";
							}else{
								$sltM="";
								$sltN="selected";
							}
						?>
                        	<select name="member_type">
                            	<option value="M" <?= $sltM ?>>Member</option>
                                <option value="N" <?= $sltN ?>>Normal User</option>                            
                            </select>
                        
                        </td>
                    </tr>
                    
					<tr>
						<td height="20" colspan="3"><br><br><strong>Personal Information</strong></td>
					</tr>
					<tr>
						<td>Name<font color="#FF0000">*</font></td><td>:</td><td><input type="text" class='text' size="30" maxlength="50" name="name" value="<?= $a['name'] ?>"></td>
					</tr>
					<?
						if($a['gender']=="male")
						{
							$malechk="checked";
							$femalechk="";
						}
						else
						{
							$malechk="";
							$femalechk="checked";
						}
					?>
					<tr>
						<td>Gender</td><td>:</td><td><input type="radio" name="sex" value="male" <?= $malechk ?>>Male<input type="radio" name="sex" value="female" <?= $femalechk ?>>Female</td>
					</tr>
					
					<tr>
						<td height="20" colspan="3"><br><br>	<strong>Contact Information</strong></td>
					</tr>
                    
					<tr>
						<td>Address</td><td>:</td><td><input type="text" class='text' size="40" maxlength="100" name="address1" value="<?= $a['address1'] ?>"></td>
					</tr>
					
                    <tr>
						<td colspan="2"></td><td><input type="text" class='text' size="40" maxlength="100" name="address2" value="<?= $a['address2'] ?>"></td>
					</tr>
					<tr>
						<td>Postcode</td><td>:</td><td><input type="text" class='text' size="7" maxlength="15" name="postcode" value="<?= $a['postcode'] ?>"></td>
					</tr>
					<tr>
						<td>City</td><td>:</td><td><input type="text" class='text' size="20" maxlength="15" name="city" value="<?= $a['city'] ?>"></td>
					</tr>
					
					<tr>
					<td>Area</td><td>:</td>
					<td>
					<div id="divResult">
					<?
						$get_place=mysql_query("select * from os_state where country_code=1 order by order_id asc");
					?>
					<select name="state" class="text">
						<option value="">Please select</option>
					<? 
						while($s=mysql_fetch_array($get_place,MYSQL_ASSOC))
						{
							if($s['id']==$a['state'])
							{
								$sslt="selected";
							}
							else
							{
								$sslt="";
							}	
					?>
						<option <?= $sslt ?> value="<?= $s['id'] ?>"><?= $s['name_eng'] ?></option>
					<? 
							
						}
					?>
					</select>
					</div>
					</td>
					</tr>
					
					<tr>
						<td>Contact number</td><td>:</td><td><input type="text" class='text' size="20" maxlength="20" name="hpnumber" value="<?= $a['hpnumber'] ?>"><br></td>
					</tr>
					
					<input type="hidden" value="<?= $id ?>" name="id">
					<tr>
						<td colspan="3" align="center"><input type="submit" value="Submit" class="button"> <input type="button" onClick="history.go(-1)" value="Back" class="button">
						</td>
					</tr>	
					</form>
				</table>
			</td>
		</tr>
	</table>
			
<? require("required/footer.php"); ?>